added SSCLI 1.0
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBVSXSaveProject / ReadMe.txt
blob652d49f1970d0e2e2acc1360513deab53aa2291a
1 ========================================================================================
2                       ProjectName: VBVSXSaveProject
3 ========================================================================================
5 ////////////////////////////////////////////////////////////////////////////////////////
6 Summary
8 This sample demonstrates that you can save an existing project to different location via
9 IDE menu. It supplies following features:
10 1. Copy the whole project to a new location.
11 2. Enable a user to select the files.
12 3. Open the new project in the current IDE.
14 NOTE: This sample only supports to copy the files in the project folder. 
15   
16 ////////////////////////////////////////////////////////////////////////////////////////
17 Requirement
19 Visual Studio 2010 and Visual Studio 2010 SDK.
21 You can download the Visual Studio 2010 SDK from
22 http://www.microsoft.com/downloads/en/details.aspx?FamilyID=47305CF4-2BEA-43C0-91CD-1B853602DCC5
25 ////////////////////////////////////////////////////////////////////////////////////////
26 Demo:
28 Step1. Open the project in VS2010.
30 Step2. Set the VBVSXSaveProject as the StartUp Project, and open its property pages. 
32        1. Select the Debug tab. Set the Start Option to Start external program and browse 
33           the devenv.exe (The default location is C:\Program Files\Microsoft Visual Studio
34           10.0\Common7\IDE\devenv.exe), and add "/rootsuffix Exp" (no quote) to the Command
35           line arguments.
36        
37        2. Select the VSIX tab, make sure "Create VSIX Container during build" and 
38           "Deploy VSIX content to Experimental Instance for debugging" are checked.
40 Step3. Build the solution.  
42 Step4. Press F5, and the Experimental Instance of Microsoft Visual Studio 2010 will 
43        be launched.
44        
45        In the VS Experimental Instance, click Tool=>Extension Manager, you will find 
46        CSVSXSaveProject is loaded.
48 Step5. In the VS Experimental Instance, open an existing project. 
49        
50 Step6. Right click a project node in the Solution Explorer, then click the menu 
51        "CSVSXSaveProject". Click this menu, the SaveProjectDialog will show.
52        
53 Step7. Select the files you want to copy in the SaveProjectDialog, check "Open new project",
54        and then click the "Save as" button and choose a folder.
56        You will find the current VS open the new project.
58 ////////////////////////////////////////////////////////////////////////////////////////
59 Code Logic:
62 A. Create a VS Package named CSVSXSaveProject.
64    You can check the detailed steps in  http://msdn.microsoft.com/en-us/library/cc138589.aspx
67 B. Add the Command to File menu and the solution explorer context menu. 
68         
69                 
70    1. Add a menu item to File menu.
71          <Group guid="guidCSVSXSaveProjectCmdSet" id="CSVSXSaveProjectGroup" priority="0x0600">
72               <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_FILE"/>
73             </Group>
74           
75          <Button guid="guidCSVSXSaveProjectCmdSet" id="cmdidCSVSXSaveProjectCommandID"
76               priority="0x0100" type="Button">
77              <Parent guid="guidCSVSXSaveProjectCmdSet" id="CSVSXSaveProjectGroup" />
78              <Icon guid="guidImages" id="bmpPic1" />
79              <Strings>
80                <CommandName>cmdidCSVSXSaveProjectCommandID</CommandName>
81                <ButtonText>CSVSXSaveProject</ButtonText>
82              </Strings>
83          </Button>
84         
85          <!--Dynamic visibility-->
86          <VisibilityConstraints>
87             <VisibilityItem guid="guidCSVSXSaveProjectCmdSet" 
88                 id="cmdidCSVSXSaveProjectCommandID" context="UICONTEXT_SolutionExists"/>
89          </VisibilityConstraints>
91    2. Add the command to the solution explorer context menu. 
92       
93         <Group guid="guidCSVSXSaveProjectContextCmdSet" id="menuidCSVSXSaveProjectContextGroup" priority="0x01">
94           <Parent guid="guidSolutionExplorerMenu" id="menuidSolutionExplorerMenu"/>
95         </Group>
97                 <Button guid="guidCSVSXSaveProjectCmdSet" id="cmdidCSVSXSaveProjectCommandID"
98                     priority="0x0100" type="Button">
99                         <Parent guid="guidCSVSXSaveProjectCmdSet" id="CSVSXSaveProjectGroup" />
100                         <Icon guid="guidImages" id="bmpPic1" />
101         
102                         <!--Add the dynamic visibility about the command menu.-->
103                         <CommandFlag>DynamicVisibility</CommandFlag>
104         
105                         <Strings>
106                           <CommandName>cmdidCSVSXSaveProjectCommandID</CommandName>
107                           <ButtonText>CSVSXSaveProject</ButtonText>
108                         </Strings>
109                  </Button>      
111 C. Get the files included in the project or in the project folder.
112    
113    1. Get the files in the project folder.
114              Public Shared Function GetFilesInProjectFolder(ByVal projectFilePath As String) As List(Of ProjectFileItem)
115             ' Get the folder that includes the project file.
116             Dim projFile As New FileInfo(projectFilePath)
117             Dim projFolder As DirectoryInfo = projFile.Directory
119             If projFolder.Exists Then
120                 ' Get all files information in project folder.
121                 Dim files = projFolder.GetFiles("*", SearchOption.AllDirectories)
123                 Return files.Select(Function(f) New ProjectFileItem With _
124                                                 {.Fileinfo = f,
125                                                  .IsUnderProjectFolder = True}).ToList()
126             Else
127                 ' The project folder does not exist.
128                 Return Nothing
129             End If
130         End Function
131     
132    2. Get the files included in the project.
134         Public Function GetIncludedFiles() As List(Of ProjectFileItem)
135             Dim files = New List(Of ProjectFileItem)()
137             ' Add the project file (*.csproj or *.vbproj...) to the list of files.
138             files.Add(New ProjectFileItem With _
139                       {.Fileinfo = New FileInfo(Project.FullName),
140                        .NeedCopy = True,
141                        .IsUnderProjectFolder = True})
143             ' Add the files included in the project.
144             For Each item As ProjectItem In Project.ProjectItems
145                 GetProjectItem(item, files)
146             Next item
148             Return files
149         End Function
151         Private Sub GetProjectItem(ByVal item As ProjectItem, ByVal files As List(Of ProjectFileItem))
152             For i As Short = 0 To item.FileCount - 1
153                 If File.Exists(item.FileNames(i)) Then
154                     Dim fileItem As New ProjectFileItem()
156                     fileItem.Fileinfo = New FileInfo(item.FileNames(i))
158                     If fileItem.FullName.StartsWith(Me.ProjectFolder.FullName,
159                                                     StringComparison.OrdinalIgnoreCase) Then
160                         fileItem.IsUnderProjectFolder = True
161                         fileItem.NeedCopy = True
162                     End If
164                     files.Add(fileItem)
165                 End If
166             Next i
168             ' Get the files of sub node under this node.
169             For Each subItem As ProjectItem In item.ProjectItems
170                 GetProjectItem(subItem, files)
171             Next subItem
172         End Sub
175 D. Design the UI of SaveProjectDialog
176    
177    This dialog is used to display the files included in the project, or under the project
178    folder. Users can select the files that need to be copied.
180 E. Open new project in the current IDE
181     
182     Dim cmd As String = String.Format(
183                             "File.OpenProject ""{0}""", newProjectPath)
185     Me.DTEObject.ExecuteCommand(cmd)  
186 /////////////////////////////////////////////////////////////////////////////////////////
187 References:
188 Walkthroughs for Customizing Visual Studio By Using VSPackages
189 http://msdn.microsoft.com/en-us/library/cc138565.aspx
191 Creating Your First VSPackage
192 http://blogs.msdn.com/b/vsxue/archive/2007/11/15/tutorial-2-creating-your-first-vspackage.aspx
194 How to: Dynamically Add Menu Items 
195 ms-help://MS.VSCC.v90/MS.VSIPCC.v90/ms.vssdk.v90/dv_vsintegration/html/d281e9c9-b289-4d64-8d0a-094bac6c333c.htm
197 Dynamic Menu Commands in Visual Studio Packages 
198 http://blogs.rev-net.com/ddewinter/2008/03/14/dynamic-menu-commands-in-visual-studio-packages-part-1/
200 Managing Solutions, Projects, and Files
201 http://msdn.microsoft.com/en-us/library/wbzbtw81.aspx
203 _Solution Members
204 http://msdn.microsoft.com/en-us/library/envdte._solution_members(v=VS.90).aspx
206 /////////////////////////////////////////////////////////////////////////////////////////